import "package:ct_pa_majordomo/config/theme_vars.dart";
import "package:ct_pa_majordomo/widgets/divider/solid_divider.dart";
import "package:flutter/material.dart";

void taiDialog({
  required BuildContext context,
  String? title,
  Widget? child,
  ValueChanged<String>? onChange,
  void Function(BuildContext)? onCancel,
  void Function(BuildContext)? onConfirm,
  String? cancelText,
  String? confirmText,
  EdgeInsetsGeometry? contentPadding,
}) async {
  showDialog(
    context: context,
    builder: (BuildContext context) {
      return Dialog(
        shape: const RoundedRectangleBorder(
          borderRadius: BorderRadius.all(Radius.circular(10)),
        ),
        child: Container(
          child: ListView(
            shrinkWrap: true,
            children: [
              if (title != null ) Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Padding(
                    padding: const EdgeInsets.symmetric(vertical: 16),
                    child: Text(title, style: const TextStyle(fontSize: 16),),
                  ),
                ],
              ),
              if (title != null ) const SolidDivider(),
              if (child != null) Padding(
                padding: contentPadding ?? const EdgeInsets.symmetric(horizontal: 10, vertical: 30),
                child: child,
              ),
              const SolidDivider(),
              SizedBox(
                height: 50,
                child: Row(
                  children: [
                    Expanded(
                      child: TextButton(
                        onPressed: () {
                          onCancel != null ? onCancel(context) : Navigator.of(context).pop();
                        },
                        child: Text(cancelText ?? "取消", style: const TextStyle(color: ThemeVars.colorTextTer),),
                      ),
                    ),
                    const SolidDivider(direction: Axis.vertical,),
                    Expanded(
                      child: TextButton(
                        onPressed: () {
                          onConfirm != null ? onConfirm(context) : Navigator.of(context).pop();
                        },
                        child: Text(confirmText ?? "确定")
                      ),
                    ),
                  ],
                ),
              )
            ],
          ),
        ),
      );
    }
  );
}